package com.weigee.ktv.v.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.l.d.app.library.app.FragActivity;
import com.l.d.app.library.eventbus.EventSendEntity;
import com.l.d.app.library.util.ResourceUtil;
import com.l.d.app.library.util.ToastUtil;
import com.l.d.app.library.util.WindowUtil;
import com.weigee.ktv.R;
import com.weigee.ktv.m.EventTag;
import com.weigee.ktv.v.activity.ActivityUtil;
import com.weigee.ktv.v.activity.StandardActivity;
import com.weigee.ktv.v.dialog.CheckReserveRoomDialog;
import com.weigee.ktv.v.view.WrapTitleBar;

import org.simple.eventbus.Subscriber;

import butterknife.BindView;
import butterknife.OnClick;
import skin.support.widget.SkinCompatTextView;

/**
 * Created by linde on 2017/4/17.
 * 填写预定信息
 */

public class WriteReserveMessageFragment extends BaseFragment {
    @BindView(R.id.wrap_title_bar)
    WrapTitleBar mTitleBar;

    @BindView(R.id.tv_room_will_reserve)
    SkinCompatTextView m_tvRoomWillReserve;// 即将预定的房间(3~5人小包)

    private CheckReserveRoomDialog mCheckRoomDialog;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.writereservemsg_frag, container, false);
    }

    @Override
    protected void initView(View view, @Nullable Bundle savedInstanceState) {
        final Context context = view.getContext();

        mTitleBar.setTitle(ResourceUtil.string(context, R.string.title_room_reservation));
        mTitleBar.setLeftButton(View.VISIBLE, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                back();
            }
        });
        mTitleBar.setTitleRight(View.VISIBLE, ResourceUtil.string(context, R.string.tip_amount_rule), new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ToastUtil.makeTest(v.getContext(), "计费规则");
            }
        });
    }

    @OnClick(R.id.group_room_will_reserve)
    protected void onRoomReserveClick(View view) {
        // 点击修改预定房间
        mCheckRoomDialog = WindowUtil.dismiss(mCheckRoomDialog);
        mCheckRoomDialog = new CheckReserveRoomDialog();
        mCheckRoomDialog.show(getChildFragmentManager(), "CheckRoom");
    }

    @Subscriber(tag = EventTag.EVENT_CHECK_RESERVE_ROOM_RETURN)
    private void onReserveRoomReturn(EventSendEntity send) {
        String msg = send == null ? null : (String) send.msg();
        if (TextUtils.isEmpty(msg)) {
            return;
        }
        mCheckRoomDialog = WindowUtil.dismiss(mCheckRoomDialog);
        if (m_tvRoomWillReserve != null) {
            m_tvRoomWillReserve.setText(msg);
        }
    }

    @OnClick(R.id.group_check_singing_time)
    protected void onCheckSingingTimeClick(View view) {
        // 点击选择欢唱时间
        FragActivity.start(StandardActivity.class, view.getContext(), ActivityUtil.CHECK_SINGING_TIME);
    }
}
